package parser

import (
	"regexp"
	"spider/crawler/engine"
)

const cityRes = `<a href="(http://album.zhenai.com/u/[0-9]+)" [^>]*>([^<]+)</a>`

func ParseCity(contents []byte) engine.ParseResult {
	// 正则
	re := regexp.MustCompile(cityRes)
	matches := re.FindAllSubmatch(contents, -1)
	//定义一个变量
	result := engine.ParseResult{}
	for _, m := range matches {
		name := string(m[2])
		result.Items = append(result.Items, "User"+name) // 人名
		result.Requests = append(result.Requests, engine.Request{
			Url: string(m[1]), //城市的url
			// ParserFunc: ParseProfile,
			ParserFunc: func(content []byte) engine.ParseResult {
				return ParseProfile(content, name)
			},
		})
	}
	return result
}
